<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../utils/flexible.js"></script>
</head>
<style>
    * {
  box-sizing: border-box;
}

ul,
body {
  margin: 0;
  padding: 0;
  list-style: none;
}

body #header {
  width: 100%;
  height: 1.3333rem;
  background-color: #1d6dff;
  padding: 0.1333rem;
}
body #header .left {
  width: 75%;
  margin-left: 0.1333rem;
  padding: 0.1867rem 0;
  float: left;
}
body #header .left a {
  display: block;
}
body #header .left a img {
  height: 0.6667rem;
}
body #header .right {
  float: right;
  padding: 0.1867rem;
}
body #header .right a {
  display: block;
}
body #header .right a img {
  width: 0.9067rem;
  height: 0.9067rem;
}

#search {
  width: 100%;
  background-color: #fff;
  height: 1.3333rem;
  border-bottom: 0.0267rem solid #ccc;
  position: relative;
}
#search .searchbox {
  padding: 0.2667rem;
}
#search .searchbox input {
  width: 90%;
  height: 0.8rem;
  padding-left: 5%;
  border-radius: 0.4rem;
  border: none;
  background-color: #f1f1f1;
  font-size: 0.4267rem;
  outline: none;
}
.container .box {
  background-color: #f5f5f5;
  border-color: #ddd;
  border-bottom: 0;
  padding: .2667rem .4rem;
  height: 1.0557rem;
 
}
.container .box h3:nth-of-type(1){
  font-size: .4267rem;
  height:100%;
  cursor:pointer;
  height: 1.0024rem;
  text-decoration: none;
  color: #333;
}
.container .box h3:nth-of-type(2){
   padding: 0 .4rem;
   margin: 0 auto;
   height: 3.28rem;
}
.container .box h3:nth-of-type(2) .content{
  height: 3.2rem;
  margin: 0 .4rem;
}
.container .box h3:nth-of-type(2) .content li{
  text-align: center;
  height: 1.0667rem;
  line-height: 1.0667rem;
  border-right: .0267rem solid #ccc;
  border-bottom: .0267rem solid #ccc;
  overflow:hidden;
  width: 25%;
  float:left;
}
</style>
<body>
    <header id="header">
        <div class="left">
            <a href="../index.html"><img src="http://chst.vip:8081/for-stu/wfzh/images/header_logo.png" width="70" alt=""></a>
        </div>
        <div class="right"><a href="#"><img src="../images/header_app.png" alt="" width="34"></a>
        </div>
    </header>
    <section id="search">
        <div class="searchbox">
            <input type="text" name placeholder="请输入你想比价的产品">
        </div>
        <div class="button">
        </div>
    </section>
    <ul class="container">

    </ul>
</body>
</html>
<script src="../utils/utils.js"></script>
<script src='https://code.jquery.com/jquery-3.6.0.min.js'></script>
<script>
   let uu = document.querySelector('.container')
   let el=""
   fetch('http://chst.vip:1234/api/getcategorytitle')
   .then(body => body.json())
   .then(res=>{
      //  console.log(res)
      let r=res.result
      console.log(r)
      r.forEach(item => {
          console.log(item.title)
          el+=`
      <li class="box">
        <h3>${item.title}<h3>
        <ol class="content"></ol>
      </li>
      `
      fetch(`http://chst.vip:1234/api/getcategory?titleid=${item.titleId}`)
      .then(body => body.json())
      .then(res => {
        let sth = ''
        res.result.forEach(el => {
            sth += `<li>${el.category}</li>`
        })
        console.log(item.titleId)
        $(`.container .box .content:eq(${item.titleId})`).html(sth)
      })
      }) 
      $('.container').html(el)
   })

  $('.container').find('.content').slideUp(0, function () {
        $('.container').css('display', 'block')
        $('.content').prop('flag', false)
    })

    $('.container').on('click', 'li', function () {
        // console.log($(this))
        // console.log($(this).find('.content').prop('flag'))

        //获取当前的开关状态 如果是true 说明自己已经展开了 要收起来
        let flag = $(this).find('.content').prop('flag')
        if (flag) {
            // console.log(123123)
            $(this).find('.content').slideUp(200).prop('flag', false)
            return
        }

        $(this).find('.content').slideDown(200).prop('flag', true).parent().siblings().find('.content').slideUp(200).prop('flag', false)
    })
</script>